package com.coda.app.service.impl;

import com.coda.app.mapper.*;
import com.coda.app.service.ApartmentService;
import com.coda.appVo.apartment.ApartmentDetailVo;
import com.coda.appVo.graph.GraphVo;
import com.coda.entity.ApartmentInfo;
import com.coda.entity.FacilityInfo;
import com.coda.entity.LabelInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class ApartmentServiceImpl implements ApartmentService {

    @Autowired
    private ApartmentMapper apartmentMapper;
    @Autowired
    private GraphMapper graphMapper;
    @Autowired
    private LabelMapper labelMapper;
    @Autowired
    private FacilityMapper facilityMapper;
    @Autowired
    private RoomMapper roomMapper;

    /**
     * 根据id查询公寓详细信息
     * @param id
     * @return
     */
    @Override
    public ApartmentDetailVo getDetailById(Long id) {
        //获取公寓基本信息
        ApartmentInfo apartmentinfo = apartmentMapper.getApartmentById(id);
        //获取图片列表
        List<GraphVo> graphVoList = graphMapper.getGraph(id,1);
        //获取标签信息
        List<LabelInfo> labelInfoList = labelMapper.getApartmentLabel(id);
        //获取配套信息
        List<FacilityInfo> facilityInfoList = facilityMapper.getApartmentFacility(id);
        //获取公寓中最小金额
        BigDecimal minMoney = roomMapper.getMin(id);

        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
        BeanUtils.copyProperties(apartmentinfo,apartmentDetailVo);
        apartmentDetailVo.setGraphVoList(graphVoList);
        apartmentDetailVo.setLabelInfoList(labelInfoList);
        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        apartmentDetailVo.setMinRent(minMoney);
        return apartmentDetailVo;
    }
}
